package com.mic.yzzn.plc.core.control.datastructure;

import com.mic.yzzn.plc.common.instructions.basic.PLCRequestInstruction;

/**
 * Created by ASH on 16/7/18.
 *
 * 表示以 COM 口采集的 PLC 的配置类
 */
public class COMStationConfig extends PLCStationConfig {
    /** 波特率 */
    private int baudRate;
    /** 数据位数 */
    private int dataBits;
    /** 停止位 */
    private int stopBit;
    /** 奇偶校验 */
    private int parity;
    /** 串口名称 */
    private String name;

    public COMStationConfig(int baudRate, int dataBits, int stopBit, int parity, String name) {
        this.baudRate = baudRate;
        this.dataBits = dataBits;
        this.stopBit = stopBit;
        this.parity = parity;
        this.name = name;
    }

    @Override
    public String id()
    {
        StringBuffer stringBuffer = new StringBuffer(name);
        stringBuffer.append("-");
        stringBuffer.append(locationNumber);

        // COM1-01

        return stringBuffer.toString();
    }

    @Override
    public String toString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append("baudRate: " + baudRate + '\n');
        buffer.append("dataBits: " + dataBits + '\n');
        buffer.append("locationNumber: " +locationNumber + '\n');
        buffer.append("hash: " + XMLFieldHashCode + '\n');
        buffer.append("isUpdate: " + updateTime + '\n');
        buffer.append("overDue: " + overdue + '\n');
        for (PLCRequestInstruction ins : instructionList)
        {
            buffer.append(ins.toString().substring(0, ins.toString().length()) + '\n');
        }

        return buffer.toString();
    }

    public int getBaudRate() {
        return baudRate;
    }

    public void setBaudRate(int baudRate) {
        this.baudRate = baudRate;
    }

    public int getDataBits() {
        return dataBits;
    }

    public void setDataBits(int dataBits) {
        this.dataBits = dataBits;
    }

    public int getStopBit() {
        return stopBit;
    }

    public void setStopBit(int stopBit) {
        this.stopBit = stopBit;
    }

    public int getParity() {
        return parity;
    }

    public void setParity(int parity) {
        this.parity = parity;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
